package com.collect.zambia.zhiScene.zhiWidget.zhiMenuView;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.collect.zambia.R;

public class CFMenuFaceRecogView extends LinearLayout {

    private final Context mContext;
    private View mView;
    private String mainText;
    private int iconResId = R.drawable.cf_ic_cf_37;

    TextView tv_main_title;
    ImageView iv_icon;

    private CFOnMenuItemDidChangedListener onMenuItemDidChangedListener;

    public CFMenuFaceRecogView(Context context) {
        this(context, null);
    }

    public CFMenuFaceRecogView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CFMenuFaceRecogView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.mContext = context;

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CFMenuFaceRecogView);
        mainText = typedArray.getString(R.styleable.CFMenuFaceRecogView_mainText);
        iconResId = typedArray.getResourceId(R.styleable.CFMenuFaceRecogView_icon, R.drawable.cf_ic_cf_37);
        typedArray.recycle();

        initView();
    }

    /**
     * 初始化组件数据
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:43
     */
    private void initView() {
        mView = View.inflate(mContext, R.layout.view_menu_face_recog, this);
        iv_icon = findViewById(R.id.iv_icon);
        tv_main_title = findViewById(R.id.tv_main_title);

        iv_icon.setImageResource(iconResId);

        tv_main_title.setText(mainText);
    }

    /**
     * 设置显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public void setText(String text){
        mainText = text;
        tv_main_title.setText(mainText);
    }

    /**
     * 获取显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public String getText(){
        return tv_main_title.getText().toString().trim();
    }


    /**
     * 设置监听
     * @type  method
     * @author liwenjie
     * @creatTime 2019-11-04 10:15
     */
    public void setCFOnMenuItemDidChangedListener(CFOnMenuItemDidChangedListener onMenuItemDidChangedListener){
        this.onMenuItemDidChangedListener = onMenuItemDidChangedListener;
    }

    public interface CFOnMenuItemDidChangedListener {
        void OnMenuItemDidChanged(String item);
    }
}
